#include "kubiki.h"
const int n_gran = 6;
using namespace std;

int main() {
	freopen( "input.txt", "r", stdin );
	int n;
	string str;
	cin >> str;
	cin >> n;
	vector< CCube > cubes;
	for( int i = 0; i < n; ++i ) {
		vector< char > vec;
		for( int j = 0; j < n_gran; ++j ) {
			char ch;
			cin >> ch;
			vec.push_back( ch );
		} 
		CCube cub( vec );
		cubes.push_back( cub );
	}
	CAkinator ans;
	freopen( "output.txt", "w", stdout );
	if( ans.HaveSolution( str, cubes ) ) {
		cout << "YES" << endl;
		vector< int > sol = ans.GetSolution();
		for( size_t i = 0; i < sol.size(); ++i ) 
			cout << sol[i] << " ";
	}
	else
		cout << "NO" << endl;
	return 0;
}